home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / vbcc / vbc.h < prev   
C/C++ Source or Header  |  1995-11-23  |  12KB  |  444 lines

  1. #include <stdlib.h>
  2. #include <limits.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stddef.h>
  6. #include <stdarg.h>
  7.  
  8. #include "machine.h"
  9.  
  10. #define eval_constn(a) eval_const(&a->val,a->ntyp->flags)
  11.  
  12. struct Typ{
  13.     int flags;
  14.     struct Typ *next;
  15.     struct struct_declaration *exact;
  16.     int size;
  17. };
  18. #define TYPS sizeof(struct Typ)
  19.  
  20. #define CHAR 1
  21. #define SHORT 2
  22. #define INT 3
  23. #define LONG 4
  24. #define FLOAT 5
  25. #define DOUBLE 6
  26. #define VOID 7
  27. #define POINTER 8
  28. #define ARRAY 9
  29. #define STRUCT 10
  30. #define UNION 11
  31. #define ENUM 12
  32. #define FUNKT 13
  33. #define UNSIGNED 16
  34. #define CONST 64
  35. #define VOLATILE 128
  36. #define UNCOMPLETE 256
  37.  
  38. struct identifier_list{
  39.     char *identifier;
  40.     int length;
  41.     struct identifier_list *next;
  42. };
  43. struct Var{
  44.     int storage_class,priority,flags;
  45.     char *identifier;
  46.     int nesting,offset;
  47.     struct Typ *vtyp;
  48.     struct const_list *clist;
  49.     struct Var *next;
  50. };
  51. #define USEDASSOURCE 1
  52. #define USEDASDEST 2
  53. #define DEFINED 4
  54. #define USEDASADR 8
  55. #define GENERATED 16
  56. #define CONVPARAMETER 32
  57. #define TENTATIVE 64
  58.  
  59. struct struct_list{
  60.     char *identifier;
  61.     struct Typ *styp;
  62.     int storage_class;
  63. };
  64. struct struct_declaration{
  65.     int count,flags;
  66.     struct struct_declaration *next;
  67.     struct struct_list sl[1];
  68. };
  69. struct struct_identifier{
  70. /*    int flags;*/
  71.     char *identifier;
  72.     struct struct_declaration *sd;
  73.     struct struct_identifier *next;
  74. };
  75.  
  76. struct obj{
  77.     int flags,reg;
  78.     struct Var *v;
  79.     struct AddressingMode *am;
  80.     union atyps{
  81.         zchar vchar;
  82.         zuchar vuchar;
  83.         zshort vshort;
  84.         zushort vushort;
  85.         zint vint;
  86.         zuint vuint;
  87.         zlong vlong;
  88.         zulong vulong;
  89.         zfloat vfloat;
  90.         zdouble vdouble;
  91.         zpointer vpointer;
  92.     }val;
  93. };
  94.  
  95. struct node{
  96.     int flags,lvalue,sidefx;
  97.     struct Typ *ntyp;
  98.     struct node *left;
  99.     struct node *right;
  100.     struct argument_list *alist;
  101.     char *identifier;
  102.     union atyps val;
  103.     struct obj o;
  104. /*  es muss noch sowas wie struct internal_object * dazu    */
  105. };
  106.  
  107. typedef struct node *np;
  108.  
  109. #define NODES sizeof(struct node)
  110.  
  111. #define KOMMA 1
  112. #define ASSIGN 2
  113. #define ASSIGNADD 3
  114. #define ASSIGNSUB 4
  115. #define ASSIGNMULT 5
  116. #define ASSIGNDIV 6
  117. #define ASSIGNMOD 7
  118. #define ASSIGNAND 8
  119. #define ASSIGNXOR 9
  120. #define ASSIGNOR 10
  121. #define ASSIGNLSHIFT 11
  122. #define ASSIGNRSHIFT 12
  123. #define COND 13
  124. #define LOR 14
  125. #define LAND 15
  126. #define OR 16
  127. #define XOR 17
  128. #define AND 18
  129. #define EQUAL 19
  130. #define INEQUAL 20
  131. #define LESS 21
  132. #define LESSEQ 22
  133. #define GREATER 23
  134. #define GREATEREQ 24
  135. #define LSHIFT 25
  136. #define RSHIFT 26
  137. #define ADD 27
  138. #define SUB 28
  139. #define MULT 29
  140. #define DIV 30
  141. #define MOD 31
  142. #define NEGATION 32
  143. #define KOMPLEMENT 33
  144. #define PREINC 34
  145. #define POSTINC 35
  146. #define PREDEC 36
  147. #define POSTDEC 37
  148. #define MINUS 38
  149. #define CONTENT 39
  150. #define ADDRESS 40
  151. #define CAST 41
  152. #define CALL 42
  153. #define INDEX 43
  154. #define DPSTRUCT 44
  155. #define DSTRUCT 45
  156. #define IDENTIFIER 46
  157. #define CEXPR 47
  158. #define STRING 48
  159. #define MEMBER 49
  160. #define CONVCHAR 50
  161. #define CONVSHORT 51
  162. #define CONVINT 52
  163. #define CONVLONG 53
  164. #define CONVFLOAT 54
  165. #define CONVDOUBLE 55
  166. #define CONVVOID 56
  167. #define CONVPOINTER 57
  168. #define CONVUCHAR 58
  169. #define CONVUSHORT 59
  170. #define CONVUINT 60
  171. #define CONVULONG 61
  172. #define ADDRESSA 62
  173. #define FIRSTELEMENT 63
  174. #define PMULT 64
  175. #define ALLOCREG 65
  176. #define FREEREG 66
  177. #define PCEXPR 67
  178. #define TEST 68
  179. #define LABEL 69
  180. #define BEQ 70
  181. #define BNE 71
  182. #define BLT 72
  183. #define BGE 73
  184. #define BLE 74
  185. #define BGT 75
  186. #define BRA 76
  187. #define COMPARE 77
  188. #define PUSH 78
  189. #define POP 79
  190. #define ADDRESSS 80
  191. #define ADDI2P 81
  192. #define SUBIFP 82
  193. #define SUBPFP 83
  194. #define PUSHREG 84
  195. #define POPREG 85
  196. #define POPARGS 86
  197. #define SAVEREGS 87
  198. #define RESTOREREGS 88
  199. #define ILABEL 89
  200. #define DC 90
  201. #define ALIGN 91
  202. #define COLON 92
  203.  
  204. struct argument_list{
  205.     np  arg;
  206.     struct argument_list *next;
  207. };
  208.  
  209. #define AUTO 1
  210. #define REGISTER 2
  211. #define STATIC 3
  212. #define EXTERN  4
  213. #define TYPEDEF 5
  214.  
  215. #define MAXSTRUCTSIZE 20000 /* maximale Groesse fuer struct_declarations in Bytes */
  216. #define MAXI 100 /* maximale Laenge von Identifiers in Bytes    */
  217. #define MAXINPUT 2000    /* maximale Laenge einer Eingabezeile in Bytes  */
  218. #define MAXN 30 /* maximale Verschachtelung von Bloecken */
  219. #define MAXM 100 /* maximale Anzahl an Bloecken pro Funktion (grob) */
  220.  
  221. #define isalpha(c) (((c)>='a'&&(c)<='z')||((c)>='A'&&(c)<='Z'))
  222. #define isnum(c)   ((c)>='0'&&(c)<='9')
  223. #define arith(c) ((c)>=CHAR&&(c)<=DOUBLE)
  224.  
  225. extern char *typname[];
  226. extern int sizetab[];
  227. extern char *storage_class_name[];
  228. extern char *ename[];
  229.  
  230. /* Tabelle fuer alignment requirements, maschinenabhaengig */
  231. extern int align[],maxalign;
  232.  
  233. extern void error(int,...);
  234.  
  235. #define ierror(a) error(158,(a),__LINE__,__FILE__)
  236.  
  237. extern struct Typ *arith_typ(struct Typ*,struct Typ *);
  238. extern void insert_const(np);
  239. extern int int_erw(int);
  240. extern int type_expression(np),compare_pointers(struct Typ *,struct Typ *,int),
  241.     compare_sd(struct struct_declaration *,struct struct_declaration *);
  242. extern np identifier_expression(void),constant_expression(void),string_expression(void),
  243.    postfix_expression(void),unary_expression(void),cast_expression(void),
  244.    multiplicative_expression(void),additive_expression(void),
  245.    shift_expression(void),relational_expression(void),equality_expression(void),
  246.    and_expression(void),exclusive_or_expression(void),
  247.    inclusive_or_expression(void),logical_and_expression(void),
  248.    logical_or_expression(void),conditional_expression(void),
  249.    assignment_expression(void),expression(void),primary_expression(void);
  250. /* puh  */
  251. extern void pre(FILE *,np),pra(FILE *,struct argument_list *);
  252. extern void free_expression(np),free_alist(struct argument_list *);
  253. extern void prd(FILE *,struct Typ *),freetyp(struct Typ *),cpbez(char *m),cpnum(char *m),killsp(void);
  254. extern struct struct_declaration *add_sd(struct struct_declaration *);
  255. extern void free_sd(struct struct_declaration *);
  256. extern void prl(FILE *,struct struct_declaration *);
  257. extern char *add_identifier(char *,int);
  258. extern struct Typ *declarator(struct Typ *),*direct_declarator(struct Typ *),
  259.            *pointer(struct Typ *),*declaration_specifiers(void),
  260.            *clone_typ(struct Typ *);
  261. extern int declaration(int),type_uncomplete(struct Typ *);
  262. extern struct struct_declaration *find_struct(char *);
  263. extern void add_struct_identifier(char *,struct struct_declaration *);
  264. extern void free_si(struct struct_identifier *);
  265. extern char *s,*ident;
  266. extern char string[MAXINPUT],number[MAXI],buff[MAXI];
  267. extern struct struct_declaration *first_sd[MAXN],*last_sd[MAXN],*merk_sdf,*merk_sdl;
  268. extern struct struct_identifier *first_si[MAXN],*last_si[MAXN],*merk_sif,*merk_sil;
  269. extern struct identifier_list *first_ilist[MAXN],*last_ilist[MAXN],*merk_ilistf,*merk_ilistl;
  270. extern void free_ilist(struct identifier_list *);
  271. extern int nesting;
  272. extern char *empty;
  273. extern struct Var *first_var[MAXN],*last_var[MAXN],*merk_varf,*merk_varl;
  274. extern struct Var *add_var(char *,struct Typ *,int,struct const_list *);
  275. extern void free_var(struct Var *);
  276. extern void var_declaration(void);
  277. extern int storage_class_specifiers(void);
  278. extern void enter_block(void),leave_block(void);
  279. extern struct Var *find_var(char *,int);
  280. extern int szof(struct Typ *);
  281.  
  282. extern void eval_const(union atyps *,int);
  283. extern zchar vchar; extern zuchar vuchar;
  284. extern zshort vshort; extern zushort vushort;
  285. extern zint vint; extern zuint vuint;
  286. extern zlong vlong; extern zulong vulong;
  287. extern zfloat vfloat; extern zdouble vdouble;
  288. extern zpointer vpointer;
  289. extern zchar vchar2; extern zuchar vuchar2;
  290. extern zshort vshort2; extern zushort vushort2;
  291. extern zint vint2; extern zuint vuint2;
  292. extern zlong vlong2; extern zulong vulong2;
  293. extern zfloat vfloat2; extern zdouble vdouble2;
  294. extern zpointer vpointer2;
  295.  
  296. extern int usz;
  297.  
  298. extern int DEBUG,MDEBUG;
  299.  
  300. struct IC{
  301.     struct IC *prev,*next;
  302.     int code,typf;
  303.     struct obj q1,q2,z;
  304. };
  305.  
  306. #define ICS sizeof(struct IC)
  307. #define VAR 1
  308. #define KONST 2
  309. #define SCRATCH 8
  310. #define STACK 16
  311. #define DREFOBJ 32
  312. #define REG 64
  313. #define VARADR 128
  314. #define DONTREGISTERIZE 256
  315.  
  316. extern struct IC *first_ic,*last_ic;
  317. extern int regs[MAXR+1],regsa[MAXR+1],regused[MAXR+1],regscratch[MAXR+1];
  318. extern struct Var *regsv[MAXR+1];
  319.  
  320. extern void add_IC(struct IC *),free_IC(struct IC *);
  321. extern void gen_IC(np,int,int),convert(np,int),gen_label(int);
  322. extern int push_args(struct argument_list *,struct struct_declaration *,int);
  323. extern int regok(int,int,int),allocreg(int,int),freturn(struct Typ *);
  324. extern int icok(struct IC *);
  325. extern void free_reg(int);
  326. extern void pric(FILE *,struct IC *),pric2(FILE *,struct IC *);
  327. extern char *regnames[];
  328. extern void probj(FILE *,struct obj *,int,int);
  329.  
  330. extern void printzl(FILE *,zlong),printzul(FILE *,zulong),printzd(FILE *,zdouble);
  331. extern void printval(FILE *,union atyps *,int,int);
  332.  
  333. extern int label;
  334.  
  335. extern FILE *in,*out,*ic1,*ic2;
  336.  
  337. extern void statement(void),labeled_statement(void),if_statement(void);
  338. extern void switch_statement(void),while_statement(void),for_statement(void);
  339. extern void do_statement(void),goto_statement(void),continue_statement(void);
  340. extern void break_statement(void),return_statement(void);
  341. extern void expression_statement(void),compound_statement(void),raus(void);
  342. extern void translation_unit(void);
  343. extern int main(int, char *[]);
  344. extern int nocode,registerpri,looppri,currentpri;
  345.  
  346. extern void *mymalloc(size_t);
  347.  
  348. extern np makepointer(np);
  349.  
  350. extern int must_convert(np,int);
  351.  
  352. extern int switch_typ,switch_count,switch_act;
  353. struct llist{
  354.     char *identifier;
  355.     int label,flags,switch_count;
  356.     struct llist *next;
  357.     union atyps val;
  358. };
  359. #define LABELDEFINED 1
  360. #define LABELUSED 2
  361. #define LABELDEFAULT 4
  362. #define LSIZE sizeof(struct llist)
  363. extern struct llist *first_llist,*last_llist;
  364. extern struct llist *find_label(char *),*add_label(char *);
  365. extern void free_llist(struct llist *);
  366.  
  367. extern int endok,return_label,return_value,break_label;
  368. extern struct Var *return_var;
  369. extern struct Typ *return_typ;
  370. extern int local_offset[MAXN];
  371.  
  372. extern void scratch_var(struct obj *,int),get_scratch(struct obj *,int,int);
  373. extern struct obj gen_cond(int,int,int);
  374.  
  375. extern void simple_regs(void);
  376.  
  377. union ppi {char *p;long l;void (*f)(char *);};
  378.  
  379. #define USEDFLAG 1
  380. #define STRINGFLAG 2
  381. #define VALFLAG 4
  382. #define FUNCFLAG 8
  383.  
  384. #define MAXCF 30
  385. extern int c_flags[MAXCF];
  386. extern char *c_flags_name[MAXCF];
  387. extern union ppi c_flags_val[MAXCF];
  388.  
  389. extern int g_flags[MAXGF];
  390. extern char *g_flags_name[MAXGF];
  391. extern union ppi g_flags_val[MAXGF];
  392.  
  393.  
  394. extern FILE *open_out(char *,char *);
  395.  
  396. extern char *inname;
  397.  
  398. extern void gen_code(FILE *,struct IC *,struct Var *,int);
  399.  
  400. extern int init_cg(void);
  401.  
  402. extern void gen_vars(struct Var *);
  403.  
  404. extern int max_offset;
  405.  
  406. extern int function_calls;
  407.  
  408. struct const_list{
  409.     union atyps val;
  410.     np tree;
  411.     struct const_list *other,*next;
  412. };
  413. extern struct const_list *first_clist,*last_clist;
  414. #define CLS sizeof(struct const_list)
  415.  
  416. /*  Format der Tabelle fuer Fehlermeldungen */
  417. struct err_out{
  418.     char *text;
  419.     int  flags;
  420. };
  421. /*  Flags fuer err_out.flags    */
  422. #define ERROR       1
  423. #define WARNING     2
  424. #define ANSIV       4
  425. #define INTERNAL    8
  426. #define FATAL      16
  427. #define MESSAGE    32
  428. #define DONTWARN   64
  429.  
  430. extern struct err_out err_out[];
  431. extern int err_num;
  432.  
  433. extern void gen_dc(FILE *,int,struct const_list *);
  434. extern void gen_ds(FILE *,int,struct Typ *),gen_var_head(FILE *,struct Var *);
  435. extern void gen_align(FILE *,int);
  436. extern void free_clist(struct const_list *);
  437.  
  438. extern void remove_IC(struct IC *);
  439.  
  440. extern zlong t_min[];
  441. extern zulong t_max[];
  442.  
  443. extern int afterlabel;
  444.